/*
 * Core_Router.cc
 *
 *  Created on: May 20, 2011
 *      Author: ubuntu
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <omnetpp.h>

#include "mpls_qos.h"
#include "MPLSPacket.h"

#include "RAR_m.h"
#include "RAA_m.h"
#include "LSP_Cost_Update_m.h"

class Core_Router : public cSimpleModule
{

	//LSP figure 2
	LSP *Core_LSP;

	protected:
	virtual void 			initialize();
    virtual void 			handleMessage(cMessage *msg);
    virtual void 			handleMessage(MPLSPacket *msg);
    virtual void 			handleMessage(RAR *msg);
    virtual void 			handleMessage(RAA *msg);
	virtual void            handleMessage(LSP_Cost_Update *msg);


};

Define_Module(Core_Router);

void Core_Router::initialize()
{

}


void Core_Router::handleMessage(LSP_Cost_Update *msg) {}

void Core_Router::handleMessage(RAR *msg)
{
    //TODO: PHB
	if (uniform(0,1) < 0.1)
    {
        EV << "\"Losing\" message " << msg << endl;
        bubble("RAR lost");
        delete msg;
    }
    else
    {
        EV << "RAR received.\n";
        delete msg;

       // send(new cMessage("ack"), "gate$o", 1);
       // send(new cMessage("ack"), "gate$o", 0);
    }
}

void Core_Router::handleMessage(RAA *msg)
{
    //TODO: PHB
	if (uniform(0,1) < 0.1)
    {
        EV << "\"Losing\" message " << msg << endl;
        bubble("RAA lost");
        delete msg;
    }
    else
    {
        EV << "RAA received.\n";
         delete msg;

       // send(new cMessage("ack"), "gate$o", 1);
       // send(new cMessage("ack"), "gate$o", 0);
    }
}


void Core_Router::handleMessage(cMessage *msg)
{
    //TODO: PHB
	if (uniform(0,1) < 0.1)
    {
        EV << "\"Losing\" message " << msg << endl;
        bubble("message lost");
        delete msg;
    }
    else
    {
        EV << msg << " received.\n";
        delete msg;

       // send(new cMessage("ack"), "gate$o", 0);
    }
}

void Core_Router::handleMessage(MPLSPacket *msg)
{
    if (uniform(0,1) < 0.1)
    {
        EV << "\"Losing\" message " << msg << endl;
        bubble("message lost");
        delete msg;
    }
    else
    {
        EV << msg << " MPLS received.\n";

       // send(new cMessage("ack"), "gate$o", 1);
       // send(new cMessage("ack"), "gate$o", 0);
    }
}
